package com.fzfnn.scrapbook.controller;

import com.fzfnn.scrapbook.dto.JournalDto.DeleteJournalRequestDto;
import com.fzfnn.scrapbook.entity.Journal;
import com.fzfnn.scrapbook.service.JournalBasicService;
import com.fzfnn.scrapbook.util.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;


@RestController
@RequestMapping("/journal/private")
@Tag(name = "用户自己操作接口", description = "用户自己操作手账相关接口")
public class JournalBasicController {
    @Autowired
    private JournalBasicService journalbasicService;

    @PostMapping("/create")
    @Operation(summary = "创建手账")
    public R createJournal(@RequestBody Journal journal,
                           @RequestHeader("Authorization") String token) throws IOException {
        return journalbasicService.createJournal(journal, token);
    }

    @PutMapping("/update")
    @Operation(summary = "更新手账")
    public R updateJournal(@RequestBody Journal journal,
                           @RequestHeader("Authorization") String token) throws IOException {
        return journalbasicService.updateJournal(journal, token);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除手账")
    public R deleteJournal(@RequestBody DeleteJournalRequestDto deleteJournalRequestDto,
                           @RequestHeader("Authorization") String token) {
        return journalbasicService.deleteJournal(deleteJournalRequestDto.getJournalId(), token);
    }
    @PatchMapping("/private/toggle-visibility/{journalId}")
    @Operation(summary = "切换手账可见性")
    public R toggleVisibility(@PathVariable Integer journalId,@RequestHeader("Authorization")String token) {
      return journalbasicService.toggleVisibility(journalId,  token);
    }

}
